home *** CD-ROM | disk | FTP | other *** search
- #include <graphics.h>
- #include <stdlib.h>
-
- main()
- {
- int graphdriver = DETECT, graphmode;
- int maxcolor, color;
- char buffer[80];
-
- /* Initialize the graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- /* Now keep switching background colors randomly */
- maxcolor = getmaxcolor();
- /* Initialize random number generator */
- randomize();
- outtextxy(10,20, "Demonstrating setcolor");
- outtextxy(10,30, "Press any key to exit");
- while (!kbhit())
- {
- color = random(maxcolor);
- setcolor(color);
- rectangle(50,50, 150,90);
- sprintf(buffer, "Color number %2d", color);
- /* Erase the area where color number will be shown */
- setfillstyle(EMPTY_FILL, color);
- bar(50,100, 50+textwidth(buffer), 100+2*textheight(buffer));
- setcolor(WHITE);
- outtextxy(50,100+textheight("H"), buffer);
- delay(1000); /* Pause for 1 second */
- /* Wait for 1 second, then exit */
- delay(1000);
- closegraph();
- }
- }